package com.zhucan.account.application.query.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * author: zhuCan
 * date: 2020/8/5 10:38
 * description:
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PageDTO<T> {

  private Integer page;

  private Integer perPage;

  private Long totalNum;

  private Integer totalPage;

  private List<T> result;

  public static <S>PageDTO<S> of(Page<S> page){
    return PageDTO.<S>builder()
        .page(page.getNumber())
        .perPage(page.getSize())
        .totalNum(page.getTotalElements())
        .totalPage(page.getTotalPages())
        .build();
  }

}
